package com.coder.timer;

import java.util.Date;

import org.apache.log4j.Logger;

import com.coder.action.UserAction;
import com.coder.model.DayIsa;
import com.coder.model.MonthIsa;
import com.coder.service.IsaService;
import com.coder.utils.DateUtilMy;

public class CalAverage {
	
	private IsaService isaService;
	private static final Logger LOGGER = Logger.getLogger(UserAction.class);

	
	public void yesterdayAvg(){
		LOGGER.info("即将开始计算昨天的Isa数据的平均值, 现在时间: "+DateUtilMy.secondFormat.format(new Date()));
		
		//首先获得今天，然后减去一天的毫秒数24*60*60*1000=86400000
		Date yesterday = new Date((new Date()).getTime()-86400000);
		DayIsa[] dayIsas = isaService.saveAvgIsaOfaDay(yesterday);
		if(dayIsas==null){
			LOGGER.info("没有昨天的Isa数据。");
		}
	}

	public void lastMonthAvg(){
		LOGGER.info("即将计算上个月的Isa数据的平均值，现在时间： "+DateUtilMy.secondFormat.format(new Date()));
		Date yesterday = new Date((new Date()).getTime()-86400000);
		String lastMonth = DateUtilMy.monthFormat.format(yesterday);
		
		LOGGER.info("月份："+lastMonth);
		MonthIsa[] monthIsas = isaService.saveAvgIsaOfaMonth(lastMonth);
		if(monthIsas==null){
			LOGGER.info("没有上个月的数据");
		}
	}
	
	public IsaService getIsaService() {
		return isaService;
	}

	public void setIsaService(IsaService isaService) {
		this.isaService = isaService;
	}
}
